using micromsg;
using MicroMsg.Common.Event;
using MicroMsg.Common.Utils;
using MicroMsg.Manager;
using MicroMsg.Protocol;
using System;
using System.Collections.Generic;
namespace MicroMsg.Scene.ChatRoom
{
	public class NetSceneAddChatRoomMember : NetSceneBaseEx<AddChatRoomMemberRequest, AddChatRoomMemberResponse, AddChatRoomMemberRequest.Builder>
	{
		private const string TAG = "NetSceneAddChatRoomMember";
		public List<string> invalidUsernameList
		{
			get;
			set;
		}
		public List<string> memeberBlackList
		{
			get;
			set;
		}
		public List<string> notExistUserList
		{
			get;
			set;
		}
		public List<string> verifyUserList
		{
			get;
			set;
		}
		public NetSceneAddChatRoomMember()
		{
			this.invalidUsernameList = new List<string>();
			this.memeberBlackList = new List<string>();
			this.notExistUserList = new List<string>();
			this.verifyUserList = new List<string>();
		}
		public bool doScene(string chatRoomName, List<string> memberList)
		{
			if (memberList != null && memberList.get_Count() != 0 && !string.IsNullOrEmpty(chatRoomName))
			{
				Log.smethod_4("NetSceneAddChatRoomMember", "doscene begin");
				base.beginBuilder();
				this.mBuilder.BaseRequest = NetSceneBase.makeBaseRequest(36);
				this.mBuilder.ChatRoomName = Util.toSKString(chatRoomName);
				using (List<string>.Enumerator enumerator = memberList.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						string current = enumerator.get_Current();
						this.mBuilder.MemberListList.Add(MemberReq.CreateBuilder().SetMemberName(Util.toSKString(current)).Build());
					}
				}
				this.mBuilder.MemberCount = (uint)memberList.get_Count();
				this.mSessionPack.mCmdID = 36;
				base.endBuilder();
				return true;
			}
			Log.smethod_5("NetSceneAddChatRoomMember", "doScene,invalid input para");
			return false;
		}
		protected override void onFailed(AddChatRoomMemberRequest request, AddChatRoomMemberResponse response)
		{
			Log.smethod_1("NetSceneAddChatRoomMember", "send AddChatRoomMemberRequest failed");
			EventCenter.postEvent(EventConst.ON_NETSCENE_ADD_CHATROOM_MEMBER_ERR, new NetSceneAddChatRoomMemberResult
			{
				retCode = RetConst.MM_ERR_CLIENT,
				sceneAddChatRoomMember = this
			}, null);
		}
		protected override void onSuccess(AddChatRoomMemberRequest request, AddChatRoomMemberResponse response)
		{
			Log.smethod_4("NetSceneAddChatRoomMember", "doscene respone sucess");
			RetConst ret = (RetConst)response.BaseResponse.Ret;
			NetSceneAddChatRoomMemberResult netSceneAddChatRoomMemberResult = new NetSceneAddChatRoomMemberResult();
			netSceneAddChatRoomMemberResult.retCode = (RetConst)response.BaseResponse.Ret;
			netSceneAddChatRoomMemberResult.sceneAddChatRoomMember = this;
			if (netSceneAddChatRoomMemberResult.retCode == RetConst.MM_ERR_MEMBER_TOOMUCH)
			{
				Log.smethod_5("NetSceneAddChatRoomMember", "send AddChatRoomMemberRequest failed ret =" + ret);
				string @string = response.BaseResponse.ErrMsg.String;
				try
				{
					string[] array = @string.Split(new char[]
					{
						','
					});
					if (array.Length == 3)
					{
						netSceneAddChatRoomMemberResult.requestMemberCount = Convert.ToUInt32(array[1]);
						netSceneAddChatRoomMemberResult.maxMemberCount = Convert.ToUInt32(array[2]);
					}
					else
					{
						Log.smethod_1("NetSceneAddChatRoomMember", "get maxMemberCount from errmsg failed, maxMemberCount not exist in errmsg");
					}
				}
				catch (Exception ex)
				{
					Log.smethod_1("NetSceneAddChatRoomMember", "get maxMemberCount from errmsg failed" + ex);
				}
				EventCenter.postEvent(EventConst.ON_NETSCENE_ADD_CHATROOM_MEMBER_ERR, netSceneAddChatRoomMemberResult, null);
				return;
			}
			if (netSceneAddChatRoomMemberResult.retCode != RetConst.MM_OK)
			{
				Log.smethod_1("NetSceneAddChatRoomMember", "send AddChatRoomMemberRequest failed ret =" + ret);
				EventCenter.postEvent(EventConst.ON_NETSCENE_ADD_CHATROOM_MEMBER_ERR, netSceneAddChatRoomMemberResult, null);
				return;
			}
			netSceneAddChatRoomMemberResult.retCode = ChatRoomMgr.checkMemberStatusFromMemberList(this.invalidUsernameList, this.memeberBlackList, this.notExistUserList, this.verifyUserList, response.MemberListList);
			if (netSceneAddChatRoomMemberResult.retCode != RetConst.MM_OK)
			{
				Log.smethod_1("NetSceneAddChatRoomMember", "send checkMemberStatusFromMemberList failed ret =" + netSceneAddChatRoomMemberResult.retCode);
				EventCenter.postEvent(EventConst.ON_NETSCENE_ADD_CHATROOM_MEMBER_ERR, netSceneAddChatRoomMemberResult, null);
				return;
			}
			if (!ChatRoomMgr.addChatroomMember(request.ChatRoomName.String, response))
			{
				Log.smethod_1("NetSceneAddChatRoomMember", "addChatroomMember : fail");
				EventCenter.postEvent(EventConst.ON_NETSCENE_ADD_CHATROOM_MEMBER_ERR, netSceneAddChatRoomMemberResult, null);
				return;
			}
			Log.smethod_4("NetSceneAddChatRoomMember", "doscene post sucess");
			EventCenter.postEvent(EventConst.ON_NETSCENE_ADD_CHATROOM_MEMBER_SUCCESS, netSceneAddChatRoomMemberResult, null);
		}
	}
}
